<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/plugins/layui/css/layui.css}">
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" id="name" name="name" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" id="pass" name="pass" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">出生日期</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" id="birthday" name="birthday" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-inline layui-input-wrap">
            <select name="deptId" id="deptId" th:with="depts=${@deptService.getDeptList()}">
                <option>请选择</option>
                <option th:each="dept:${depts}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属班级</label>
        <div class="layui-input-inline layui-input-wrap">
            <select name="classId" id="classId" th:with="classes=${@classService.getClassList()}">
                <option>请选择</option>
                <option th:each="class:${classes}" th:value="${class.classId}" th:text="${class.className}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属年级</label>
        <div class="layui-input-inline layui-input-wrap">
            <select name="gradeId" id="gradeId" th:with="grades=${@gradeService.getGradeList()}">
                <option>请选择</option>
                <option th:each="grade:${grades}" th:value="${grade.gradeId}" th:text="${grade.gradeName}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <input type="hidden" id="roleIds" name="roleIds" value="">
        <div class="" th:with="roles=${@roleService.list()}">
           <input lay-filter="role-filter" type="checkbox" name="roleId" th:each="role:${roles}" th:text="${role.roleName}" th:value="${role.roleId}" lay-skin="primary">
        </div>
    </div>

</form>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/plugins/layui/layui.js}"></script>
<script>
    layui.use(function(){
        var laydate = layui.laydate;
        var form = layui.form;
        var $ = layui.$;
        laydate.render({
            elem: '#birthday',
            type: 'date'
        });

        form.on('checkbox(role-filter)', function(data){
            //每点击复选框，都遍历所有复选框的选中值
            var checkeds = "";
            $("input[name=roleId]:checked").each(function(i){
                if(i==0){
                    checkeds = $(this).val();
                }else{
                    checkeds += ","+$(this).val();
                }
            })
            $("#roleIds").val(checkeds);
        });
    });
</script>
</body>
</html>
